package com.czxy.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.czxy.rbac.SysPermission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

@Mapper
public interface SysPermissionMapper extends BaseMapper<SysPermission> {


    @Select("select * from sys_permission where id in (select perm_id from sys_role_permission where role_id = #{roleId}) and parent_id !=0")
    public List<Integer> findPermIdByRoleId(Integer roleId);


    @Select("select * from sys_permission where id in \n" +
            "\t(select perm_id from sys_role_permission where role_id in \n" +
            "\t\t(select id from sys_role where id in (select role_id from sys_user_role where user_id = #{userId})))\n" +
            "                             and parent_id = #{parentId}")
    public Set<SysPermission> findByUserIdAndParentId(@Param("userId") Integer userId, @Param("parentId") Integer parentId);




}